﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using RiderShop.Mobile.Modle;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Products.Enumerations;
using System.Collections.Specialized;
using RiderShop.Mobile.Common.Component;
using Kevin.Shop.Business.Comments.Components;
using RiderShop.Mobile.Modle;
using RiderShop.Mobile.ServiceEntity.Product;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Shipping;
using Kevin.Shop.Business.Core.Components.Responser;
using RiderShop.Mobile.ServiceEntity.MyAccount;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.ServiceEntity;

namespace RiderShop.WebSite.Controllers
{
    public partial class ContentController : ThemeController
    {
        #region 得到文章的每个分类和每个分类的文章列表
        /// <summary>
        /// 得到文章的每个分类和每个分类的标题
        /// </summary>
        /// <returns></returns>
        public ActionResult ContentInfo(int contentCategoryId = 0)
        {
            ContentModel contentModel = new ContentModel();
            contentModel.GetCategoriesAndArticleInfo();
            if (contentModel.CategoriesAndArticleList != null)
            {
                if (contentCategoryId == 0)
                {
                    contentCategoryId = contentModel.CategoriesAndArticleList.FirstOrDefault().ContentCategoryId;
                }
                contentModel.GetArticleInfoByContentCategoryId(contentCategoryId);
            }
            return View(WebClientContext.Current.SiteTheme, "Content", "ContentInfo", WebClientContext.Current.CacheKeyDefaultMasterPage, contentModel);
        }
        #endregion

        #region 通过文章的分类编号得到该分类的文章列表
        /// <summary>
        /// 通过文章的分类编号得到该分类的文章列表
        /// </summary>
        /// <param name="contentCategoryId">文章分类编号</param>
        /// <returns></returns>
        public ActionResult ContentInfoByContentCategoryId(int contentCategoryId)
        {
            ContentModel contentModel = new ContentModel();
            contentModel.GetArticleInfoByContentCategoryId(contentCategoryId);

            return View(WebClientContext.Current.SiteTheme, "Content", "ContentDetail", WebClientContext.Current.CacheKeyDefaultMasterPage, contentModel);
        }

        /// <summary>
        /// 通过文章的分类编号得到该分类的文章列表
        /// </summary>
        /// <param name="contentCategoryId">文章分类编号</param>
        /// <returns></returns>
        public JsonResult ContentInfoByContentCategoryIdByAjaxRequest(int contentCategoryId = 6)
        {
            ContentModel contentModel = new ContentModel();
            contentModel.GetArticleInfoByContentCategoryId(contentCategoryId);

            return Json(contentModel.ArticleList,JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 得到具体的文章内容
        /// <summary>
        ///  得到具体的文章内容
        /// </summary>
        /// <param name="articleId">文章编号</param>
        /// <returns></returns>
        public ActionResult ContentDetail(int articleId)
        {
            ContentModel contentModel = new ContentModel();
            List<ArticleInfo> articles = contentModel.GetArticleInfo(articleId);
            if (articles.Count > 0)
            {
                return View(WebClientContext.Current.SiteTheme, "Content", "ContentDetail", WebClientContext.Current.CacheKeyDefaultMasterPage, articles);
            }
            return View(WebClientContext.Current.SiteTheme, "Content", "ContentDetail", WebClientContext.Current.CacheKeyDefaultMasterPage, articles);
        }

        /// <summary>
        ///  得到具体的文章内容适用于ajsx请求
        /// </summary>
        /// <param name="articleId">文章编号</param>
        /// <returns></returns>
        public JsonResult ContentDetailByAjaxRequest(int articleId)
        {
            ContentModel contentModel = new ContentModel();
            List<ArticleInfo> articles = contentModel.GetArticleInfo(articleId);

            return Json(articles.FirstOrDefault(), JsonRequestBehavior.AllowGet);
       }
        #endregion
    }
}
